package actions;

import java.util.*;
import java.sql.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.StudentModel;

import org.apache.struts.action.*;

public class ApplicationsAction extends Action
{
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		String reviewer = request.getParameter("reviewer");
		if (reviewer != null) {
			// setup applications for the given reviewer
			Vector applications = StudentModel.getApplicationsByReviewer(reviewer);
			request.getSession().setAttribute("applications", applications);
		}
		
		String discipline = request.getParameter("discipline");
		if (discipline != null) {
			// setup applications for the given discipline
			Vector applications = StudentModel.getApplicationsByDiscipline(discipline);
			request.getSession().setAttribute("applications", applications);
		}
		
		String specialization = request.getParameter("specialization");
		if (specialization != null) {
			// setup applications for the given specialization
			Vector applications = StudentModel.getApplicationsBySpecialization(specialization);
			request.getSession().setAttribute("applications", applications);
		}
		
		if (reviewer == null && discipline == null && specialization == null) {
			// if no argument is given print out all applications
			Vector applications = StudentModel.getApplications();
			request.getSession().setAttribute("applications", applications);
		}
	
		return mapping.findForward("success");
	}
}
